<template>
  <div id="app">
    <el-container>
      <!-- aside部分 -->
      <el-aside width="200">
        <!-- logo -->
        <div class="logo"></div>
        <!-- 展示侧边栏子组件 -->
        <subMenu></subMenu>
      </el-aside>
      <el-container>
        <!-- header部分 -->
        <el-header>
          <el-row type="flex" class="row-bg" justify="space-around">
            <el-col :span="6">
              <div class="grid-content left" @click="toggle">
                <i :class="collapse"></i>
              </div>
            </el-col>
            <el-col :span="6">
              <div class="grid-content middle">
                <p class="Home_header_title">千锋学员管理系统</p>
              </div>
            </el-col>
            <el-col :span="6">
              <div class="grid-content right">
                <!-- 用户头像 -->
                <el-avatar
                  shape="square"
                  :size="50"
                  :src="userheadimg"
                ></el-avatar>
                <b
                  >欢迎您:
                  <span class="nickName">{{ userInfo.nickname }}</span></b
                >

                <el-dropdown @command='command'>
                  <span class="el-dropdown-link">
                    <i class="el-icon-arrow-down el-icon--right"></i>
                  </span>
                  <el-dropdown-menu slot="dropdown">
                    <el-dropdown-item command='vipManger' icon="iconfont icon-VIP3" 
                      >vip充值</el-dropdown-item
                    >
                    <el-dropdown-item icon="iconfont icon-yonghu" command='users'
                      >账号信息</el-dropdown-item
                    >
                    <el-dropdown-item icon="iconfont icon-shuju" command='studentProfile'
                      >项目管理</el-dropdown-item
                    >
                    <el-dropdown-item
                      icon="iconfont icon-tuichu"
                      class="quit"
                      @click.native="quit"
                      >退出</el-dropdown-item
                    >
                  </el-dropdown-menu>
                </el-dropdown>
              </div>
            </el-col>
          </el-row>
        </el-header>
        <!-- main部分 -->
        <el-main>
          <!-- 展示面包屑 -->
          <el-breadcrumb separator=">">
            <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
            <el-breadcrumb-item
              v-for="item in breadCrumb"
              :key="item.name"
              :to="{ name: item.name }"
              >{{ item.meta.name }}</el-breadcrumb-item
            >
          </el-breadcrumb>
          <!-- 展示home下面的子路由,展示在main区域 -->
          <router-view></router-view>
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>

<script>
import * as api from "../../api/index"; //获取日志的api
import { mapState } from "vuex";
import subMenu from "./../../components/SubMenu"; //引入侧边栏组件
/* import recursionRoutes from '../../utils/recursionRoutes' //引入我们处理好的路由配置文件
import allRoutes from '../../router/allRoutes' //引入allrutes配置文件 */
export default {
  components: {
    subMenu, //注册称为自己的子组件
  },
  computed: {
    ...mapState(["userInfo", "isCollapse", "breadCrumb"]),
    userheadimg() {
      return this.userInfo.headimgurl
        ? this.userInfo.headimgurl
        : "https://cube.elemecdn.com/9/c2/f0ee8a3c7c9638a54940382568c9dpng.png";
    },
    collapse() {
      return this.isCollapse ? "iconfont icon-zhankai" : "iconfont icon-shouqi";
    },
  },
  mounted() {
    /*     api.loginLog()
    .then(res=>{
      console.log(res);
    }) */
    /*   api.getMenuList()
    .then(res=>{
      // console.log(111);
      console.log(res);
     console.log( recursionRoutes(allRoutes,res.data.menuList));
    }) */
  },
  data() {
    return {};
  },
  methods: {
    //command右上角用户下拉菜单触发事件
    command(routerName){
      //routerName是下拉禁单传入的路由名字
      // console.log(c);
      if(routerName){//表示如果有routerName,就让他跳转
        this.$router.push({name:routerName})

      }
    },
    //  ...mapMutations,
    quit() {
      this.$router.push("/login"); //跳转页面到登录页
      localStorage.removeItem("qf-token"); //清楚token
      // 因为动态路由addRoutes只能添加，不能删除，所以我们在退出页面的时候要重新刷新页面
      location.reload();
    },
    toggle() {
      this.$store.commit("SIDE_MENU_COLLAPSE");
    },
  },
};
</script>
<style scoped lang="less">
.el-header {
  background: linear-gradient(135deg, #4c67ff, #5635df);
  color: #fff;
  text-align: center;
  min-height: 60px !important;
  padding: 0;
}

.el-aside {
  background: linear-gradient(135deg, #4c67ff, #5635df);
  color: #333;
  text-align: center;
  .logo {
    min-height: 60px;
  }
}

.el-main {
  // background-color: pink;
  color: #333;
  text-align: center;
}

.el-container {
  margin-bottom: 40px;
  height: 100%;
}

/* header上的组件的样式 */
.el-row {
  margin-bottom: 20px;
  &:last-child {
    margin-bottom: 0;
  }
}
.el-col {
  border-radius: 4px;
}
.grid-content {
  border-radius: 4px;
  min-height: 36px;
}
.row-bg {
  padding: 10px 0;
}

.left {
  text-align: left;
  line-height: 40px;
  /deep/i {
    cursor: pointer;
    font-size: 30px;
  }
}
.middle {
  font-size: 16px;
  .Home_header_title {
    font-weight: 900;
    margin-top: 10px;
  }
}
.el-avatar {
  vertical-align: middle;
}
.right b {
  margin-left: 10px;
}
.right i {
  font-style: normal;
  margin-left: 10px;
  font-weight: 0;
  cursor: pointer;
}
.right {
  margin-top: -5px;
}
.quit {
  color: #ff69b4;
}
/deep/ .logo {
  height: 60px;
  background: linear-gradient(135deg, #4c67ff, #5635df);
  background-image: url("../../assets/logo.png");
  background-size: 80%;
  background-repeat: no-repeat;
  background-position: 50%;
}
.el-icon-arrow-down {
  color: #fff;
}
</style>
